var a = require("utils/api.js");

App({
    siteInfo: require("siteinfo.js"),
    globalData: {
        userInfo: null,
        storeInfo: null,
        openid: null,
        m_openid: null,
        location: !1,
        version_num: "2.0.66",
        share_head_mid: -1,
        share_url: "",
        now_city: "",
        now_cid: 0,
        longitude: "",
        latitude: "",
        bottom_nav: "",
        index_show_mod: 1,
        default_small_img: "/images/default_small.png",
        default_big_img: "/images/default_big.png",
        is_open_goods_video: 2,
        is_open_spike: 0
    },
    onLaunch: function() {
        var o = this;
        if (wx.getSystemInfo({
            success: function(a) {
                console.log(a), o.globalData.windowHeight = a.windowHeight, o.globalData.systemWidth = a.screenWidth, 
                o.globalData.systemHeight = a.screenHeight, a.SDKVersion.split(".")[0] < 2 && wx.showToast({
                    title: "您的微信版本过低，请升级微信后再进入",
                    icon: "none",
                    duration: 5e3
                });
            }
        }), wx.canIUse("getUpdateManager")) {
            var e = wx.getUpdateManager();
            e.onCheckForUpdate(function(a) {
                console.log(a.hasUpdate), a.hasUpdate && (e.onUpdateReady(function() {
                    wx.showModal({
                        title: "更新提示",
                        content: "新版本已经准备好，是否重启应用？",
                        showCancel: !1,
                        confirmText: "更新",
                        success: function(a) {
                            a.confirm && e.applyUpdate();
                        }
                    });
                }), e.onUpdateFailed(function() {
                    wx.hideLoading(), wx.showModal({
                        title: "升级失败",
                        content: "新版本下载失败，请检查网络！",
                        showCancel: !1
                    });
                }));
            });
        } else wx.showToast({
            title: "您的微信版本过低，可能无法正常使用小程序，请升级后进入",
            duration: 5e3,
            icon: "none"
        });
        wx.getStorage({
            key: "adsInfo",
            success: function(a) {
                wx.removeStorage({
                    key: "adsInfo"
                });
            }
        }), wx.login({
          success: function (e) {
            console.log(e);
                if (e.code) {
                    var t, n;
                    a.getOpenid({
                        code: e.code
                    }).then(function(e) {
                        console.log(e), wx.setStorage({
                            key: "openid",
                            data: e.data.openid
                        }), o.globalData.openid = e.data.openid, wx.setStorage({
                            key: "sessionkey",
                            data: e.data.sessionkey
                        }), o.globalData.enterFirst = !0, o.globalData.loadAds = !0, o.globalData.is_open_goods_video = e.data.config.is_open_goods_video, 
                        o.globalData.data_end_show_img = e.data.config.data_end_show_img, o.globalData.data_end_show_img_open = e.data.config.data_end_show_img_open, 
                        o.globalData.diy_community_name = e.data.config.diy_community_name ? e.data.config.diy_community_name : "社区", 
                        1 == e.data.config.data_end_show_img_open ? (o.globalData.default_small_img = e.data.config.default_small_img, 
                        o.globalData.default_big_img = e.data.config.default_big_img) : (o.globalData.default_small_img = "", 
                        o.globalData.default_big_img = ""), t = e.data.openid, n = e.data.sessionkey, o.getopenidBack && o.getopenidBack(e.data.openid), 
                        a.getMember({
                            openid: t
                        }).then(function(a) {
                            console.log(a), 0 != a.errno || null == a.data.m_photo || "" == a.data.m_photo || "null" == a.data.m_photo || void 0 == a.data.m_photo ? o.globalData.is_first_enter = 1 : o.globalData.is_first_enter = 2;
                        }), a.getCartNum({
                            openid: t
                        }).then(function(a) {
                            console.log(a), wx.setStorageSync("cartnum", a.data);
                        });
                    });
                } else wx.showToast({
                    title: "授权失败",
                    icon: "none",
                    duration: 3e3,
                    mask: !0
                });
            },
            fail: function() {
                wx.showToast({
                    title: "登录失败",
                    icon: "none",
                    duration: 3e3,
                    mask: !0
                });
            }
        });
    },
    onShareAppMessage: function(a) {
        var o = this;
        return {
            title: "麦芒社区团购",
            path: "/pages/index/index",
            success: function(a) {
                o.shareClick();
            },
            fail: function(a) {
                wx.showToast({
                    title: "转发失败",
                    icon: "clear",
                    duration: 2e3
                });
            }
        };
    }
});